package com.javabean;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

//普通注解 用于标识类 交由spring容器管理 默认使用类名作为id
@Component("user")
//范围注解 等价于scope属性 用于设置单例多例 默认单例
@Scope("prototype")
public class User {
    private int id;
    private String name;
    private int age;
    //自定义类型自动注入
    //先根据属性名称进行注入 没有则根据属性类型进行注入
    @Resource
    private Role r;

    public User() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Role getR() {
        return r;
    }

    public void setR(Role r) {
        this.r = r;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", r=" + r +
                '}';
    }
}
